import React from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import { ActivationDetection, ActivationEvent } from "./Components/ActivationDetection/ActivationDetection";

import { BaseModules } from "./Modules/Base/Index";
import Loading from "./Components/Loading/Loading"

/**
 * @func default 程序整体初始化入口，目前技术栈而言就是路由入口了
 * @url https://segmentfault.com/a/1190000011765141
 */

type State = {
  hasActivatation: boolean
}

class App extends React.PureComponent<{}, State> {

  readonly state: State = {
    hasActivatation: false
  }

  public handleActivation = (evt: ActivationEvent) => {
    this.setState(function () {
      return {
        hasActivatation: true
      }
    })
  }

  public render () {
    return (
      <div onClick={this.handleActivation} >
        <ActivationDetection.Provider value = {this.state.hasActivatation} >
          <Switch>

            {/* 有效组件 */}
            {
              BaseModules.map(item => {
                return (
                  <Route key={item.path} path={item.path} component={item.component} />
                )
              })
            }

            {/* 测试性质的组件, 路径以 _ 开头 */}
            <Route path='/_loading' component={ Loading } />

            {/* 通过移动到测试段落前可以覆盖测试路径的匹配, 除此外 fallback 应该保持在最尾 */}
            <Route path='*' component={() => <Redirect to="/main" />} />
          </Switch>
        </ActivationDetection.Provider>
      </div>
    )
  }
}
// export const App = withRouter(_App)

export default App
